<template>
  <div class="collect-page">
     <!-- 上拉刷新列表 -->
     <van-list  v-model="loading"  :finished="finished"  @load="onLoad">
      <!-- 拿到ajax 渲染页面 -->
      <article-item v-for="item in list " :key="item.id" :item ='item'></article-item>
    </van-list>
  </div>
</template>

<script>
import { getArticlesCollect } from '@/api/article.js'
export default {
  name: 'collect-page',
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 2
    }
  },
  methods: {
    async onLoad () {
      // 发送ajax
      const data = await getArticlesCollect({
        page: this.page
      })
      console.log(data)
      this.list.push(...data.data.rows)
      // 当前页码自增
      this.current++
      // 加载状态结束
      this.loading = false
      // (4)判断是否全部加载完毕 (如果接口没数据，默认返回一个空数组)
      if (this.page === data.pageTotal || !data.rows.length) {
        this.finished = true
      } else {
        this.page++
      }
    }
  }
}
</script>

<style lang="less" scoped>
.collect-page {
  margin-bottom: 50px;
  margin-top: 44px;
}
</style>
